//获取应用实例
const app = getApp()
import confg from '../../utils/config';
import util from '../../utils/util';
import {
  MyTask,taskDown,shopDown
} from '../../utils/api'
Page({
  data: {
    confg:confg,
    list: [],
    curpage: 1,
    size: 10,
    isLoadMore: true,
    type:1
    // visible: false,
    // userInfo:{}
  },

  //事件处理函数
  bindViewTap: function () {

  },
  onLoad: function () {
    this.getList();
  },
  onShow: function () { 
 
  },
  onReachBottom: function () {
    if (this.data.isLoadMore) {
      this.setData({
        curpage: this.data.curpage + 1,
      })
      this.getList()
    }
  },
  // 获取首页数据
  getList(boo) {
    let da = {
      limit: this.data.size,
      type:this.data.type,
      page: this.data.curpage - 1
    }
    MyTask(da).then(res => {
      let goods = [];
      if (res.data.length < this.data.size) {
        this.setData({
          isLoadMore: false
        })
      }
      goods = this.data.list.concat(res.data)
      this.setData({
        list: goods
      })
      if(boo){wx.stopPullDownRefresh()}
    })
  },

  cutTaskTypeFn(e){
    this.setData({
      type: e.currentTarget.dataset.id,
      curpage: 1,
      list: []
    })
    this.getList();
  },
  onPullDownRefresh() {
    this.setData({
      curpage: 1,
      list: []
    })
    this.getList(true);
  },
  taskDesdoryFn(e){
    taskDown(e.currentTarget.dataset).then(res=>{
      this.setData({
        curpage: 1,
        list: []
      })
      this.getList(true);
    })
  },
  shopDesdoryFn(e){
    shopDown(e.currentTarget.dataset).then(res=>{
      this.setData({
        curpage: 1,
        list: []
      })
      this.getList(true);
    })
  },
  contentKf(){
    wx.showToast({
      title: confg.auth_text[3],
      icon: 'none',
      duration: 2000
    })
  }
})